﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "Duiw";
    Layout = "~/Views/Shared/_Genertals.cshtml";
}

<div class="Zhuyags">
    <div class="col-2 nav-item" id="divjibeng">@Resource.String48</div>
    <div class="col-2 nav-item" id="divbeizhu">@Resource.String49</div>
    <div class="col-2 nav-item" id="divtuzhi">@Resource.String50</div>
    <div class="col-2 nav-item" id="divweituo" style="display:none">@Resource.String51</div>
</div>
<div id="WT_dh_mb2" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:200px;width:300px">
    <div style="text-align: right; background-color: #84acde;"><span class="WT_qxbh2" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
    <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
        <div id="WJ_XZLJ"></div>
    </div>
    <div style="text-align:center"><button class="WT_qxbh2">@Resource.String126</button></div>
</div>
<div>
    <div id="divsw1">
        <fieldset class="boun">
            <legend class="len">申请单信息</legend>
            <div>
                <table id="BiaoTo" class="table-app">
                    @foreach (var item in ViewBag.APPH as List<Applications>)
                    {
                        <tr style="display:none"><td id="HUSNA">@(Session["jisned"])</td><td id="JNKMHNB">@item.AP_ren</td></tr>
                        <tr>
                            <td>@Resource.String429</td>
                            <td>
                                <input type="text" id="txtname" name="dan" readonly="readonly" value="@item.App_Kehu">
                            </td>
                            <td>@Resource.String430</td>
                            <td>
                                <input type="text" id="txtdan" name="dan" readonly="readonly" value="@item.AP_bian">
                            </td>
                        </tr>
                        <tr>
                            <td>@Resource.String431</td>
                            <td>
                                <input type="datetime" id="txtqishi" name="qishi" readonly="readonly" value="@item.App_qishi">
                            </td>

                            <td>@Resource.String432</td>
                            <td>
                                <input type="datetime" id="txtjeishu" name="jeishu" readonly="readonly" value="@item.App_JTime">
                            </td>
                        </tr>
                        <tr>
                            <td>
                                @Html.Label(Resource.String433):
                            </td>
                            <td>
                                <label id="hsijddd"> @item.APP_name</label>
                            </td>
                            <td>@Html.Label(Resource.String435):</td>
                            <td> @item.APP_Zhong</td>
                        </tr>
                        <tr>
                            <td>@Html.Label(Resource.String437):</td>
                            <td> @item.App_dizhi</td>
                            <td>@Html.Label(Resource.String434): </td>
                            <td>@item.App_lei</td>
                        </tr>
                        <tr>
                            <td>@Html.Label(Resource.String438):</td>
                            <td> @item.App_sho</td>
                            <td>
                                @Html.Label(@Resource.String77):
                            </td>
                            <td>
                                <lable id="Shenji">@item.APP_she</lable>
                            </td>
                        </tr>
                    }

                </table>
            </div>
        </fieldset>
    </div>
    <div id="divsw2" style="display:none">
        <div class="">
            <fieldset class="boun">
                <legend class="len">@Resource.String83</legend>
                <div id="div2_div">

                </div>
                <textarea rows="4" class="col-11" id="RZ_xznr"></textarea><br />
                <input type="button" name="name" value="@Resource.tj" id="RZ_tjrz" />
            </fieldset>
        </div>
    </div>
    @*图纸备注*@
    <div id="divsw3" style="display:none">
        <div class="">
            <fieldset class="boun">
                <legend class="len">@Resource.String84</legend>
                <table class="table tab">
                    <thead style="text-align:center;">
                        <tr style="background-color: #6e95bc">
                            <td>@Resource.String85</td>
                            <td>@Resource.String86</td>
                            <td>@Resource.String87</td>
                            <td>@Resource.String88</td>
                            <td>@Resource.String89</td>
                        </tr>
                    </thead>
                    <tbody id="div3__tb">
                    </tbody>
                </table>
            </fieldset>
        </div>
    </div>
</div>
<div>
    <table class="table tab">
        <thead>
            <tr style="text-align:center">
                <td>编号</td>
                <td>物料</td>
                <td>供应商</td>
                <td>阶梯</td>
                <td>二级分类</td>
                <td>成本价</td>
                <td>利润</td>
                <td>报价</td>
                <td>理论成本</td>
            </tr>
        </thead>
        <tbody class="BHIDNND" style="height: 304px;">
        </tbody>
    </table>
</div>
<fieldset>
    <div id="Kngsjh">

    </div>
</fieldset>
<div id="WT_dh_mb" style="display:none;position:fixed;background-color:white;top:200px;width:660px;left:300px;z-index:1000;border:1px black solid;">
    <div id="WJ_ID" style="display:none"></div>
    <table>
        <tr>
            <td>审核人：</td>
            <td id="WT_dhr"></td>
        </tr>
        <tr>
            <td>驳回理由</td>
            <td><textarea id="WT_dhly"></textarea></td>
        </tr>
        <tr>
            <td id="WT_qdbh">确定</td>
            <td id="WT_qxbh">取消</td>
        </tr>
    </table>
</div>
<input type="button" name="name" value="通过" id="dabiO1" />
<input type="button" name="name" value="驳回" id="dabiOLP" />
@*<input type="button" name="name" value="完成" id="dabokjj" />*@
<input type="button" name="name" value="返回" id="fanghui" />
<input type="button" name="name" value="物料成本" id="WLcb" />
@section scripts{
    <script>
        $(function () {
            gettuz()//搜索图纸信息
            gettbz()//搜索备注信息
            //点击切换基础信息，备注信息，图纸沟通
            $(function () {
                $("#divjibeng").click(function (e) {
                    $("#divsw1").css({ "display": "block" });
                    $("#divsw2").css({ "display": "none" });
                    $("#divsw3").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#divbeizhu").click(function (e) {
                    $("#divsw2").css({ "display": "block" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw3").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
                $("#divtuzhi").click(function (e) {
                    $("#divsw3").css({ "display": "block" });
                    $("#divsw1").css({ "display": "none" });
                    $("#divsw2").css({ "display": "none" });
                    $(this).css({ "background-color": "#fff" })
                    $(this).siblings().css({ "background-color": "#ededed" })
                })
            })
            //写入日志
            $(document).on("click", "#RZ_tjrz", function () {
                var now = new Date($.now());
                var year = (now.getFullYear()).toString();
                var month = (now.getMonth() + 1).toString();
                var date = (now.getDate()).toString();
                var hours = (now.getHours()).toString()
                var minutes = (now.getMinutes()).toString()

                //组合当前日期
                var sqrq = year + "/" + month + "/" + date + " " + hours + ":" + minutes
                var rzxx = {
                    B_Bian: $("#shenDan").val(),
                    B_BR: $('#Login_N').val(),
                    B_Date: sqrq,
                    B_bei: $('#RZ_xznr').val(),

                };
                console.log(rzxx)
                $.ajax({
                    url: "/Contracts/AddLogs",
                    type: "POST",
                    data: rzxx,
                    success: function (data) {
                        alert(data)
                        gettbz()
                    },
                    error: function (data) {
                        alert("erroer");
                    },
                })
            })
            find_inf()
            function find_inf() {
                $.ajax({
                    url: '/ShenPI/HJSP',
                    type: 'GET',
                    data: { "state": 3, "bians": $("#txtdan").val() },
                    success: function (zc) {
                        if (zc == "" || zc == null) {
                            alert("该物料未自制物料无询价记录！")

                        } else {
                            $("#Kngsjh table").remove()
                            $("#Kngsjh").append(zc)
                            //判断最小值
                            $("#Kngsjh").parent().find("tr").each(function () {
                                var shund = Number.MAX_SAFE_INTEGER;//最大值
                                $(this).children().find('span').each(function () {
                                    var ZHI = $(this).parent().children().eq(0).text()
                                    if (!isNaN(ZHI) && ZHI < shund) { // 如果value是一个数字且小于当前的最小值
                                        shund = ZHI; // 更新最小值
                                    }
                                })
                                $(this).find('input[type="radio"]').each(function () {
                                    if ($(this).prev().text() == shund) {
                                        $(this).prev().css({ "color": "#0077ff" })
                                    }
                                })
                            })
                        }

                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            //获取图纸信息
            function gettuz() {
                var kan = $("#txtdan").val();
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "App_ban": kan, "state": 3 },
                    success: function (sjik) {

                        $("#div3__tb tr").remove();
                        $.each(sjik, function (i, item) {
                            var x = item.De_dizhi
                            var $tr = $(`
                                                                                        <tr class="log_tr">
                                                                                            <td style="display:none">${item.DE_id}</td>
                                                                                            <td>${i + 1}</td>
                                                                                            <td>${item.De_dizhi}</td>
                                                                                            <td>${item.De_shijian}</td>
                                                                                            <td>${item.De_ren}</td>
                                                                                            <td><a href="#" id="log_SC">删除</a>/<a href="/Contracts/Download_file?path=${x}" id="log_SZ">下载</a></td>
                                                                                        </tr>
                                                                                        `);
                            $("#div3__tb").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }
            //获取备注信息
            function gettbz() {
                var kan = $("#shenDan").val();
                $.ajax({
                    url: "/Application/Application",
                    type: "POST",
                    data: { "App_ban": kan, "state": 4 },
                    success: function (sjik) {
                        $("#div2_div div").remove();
                        $.each(sjik, function (i, item) {
                            var $tr = $(`
                                                                                        <div>
                                                                                            <div>
                                                                                                <span>${item.B_BR}</span><span>${item.B_Date}</span>
                                                                                            </div>
                                                                                            <div>
                                                                                                ${item.B_bei}
                                                                                            </div>
                                                                                        </div>`);
                            $("#div2_div").append($tr);
                        })
                    },
                    error: function () {
                        alert("erroer");
                    },
                })
            }
        })
        //
        $(function () {
            $("#fanghui").click(function () {
                window.location.href = "/Admin/shenpiView";
            })
            //驳回按钮
            $(document).on("click", "#dabiOLP", function () {
                var Name = $("#Login_N").text()
                $("#WT_dhr").text(Name)
                $("#WT_dh_mb").show();
            })
            $(document).on("click", "#WT_qxbh", function () {
                $("#WT_dh_mb").hide();
                $("#WT_dhly").text("");
            })
            //确定驳回
            $(document).on("click", "#WT_qdbh", function () {
                var Binas = $("#txtdan").val()
                var Name = $("#Login_sf").text()
                var MMK = $("#WT_dhly").val()
                if (MMK != "") {
                    $.ajax({
                        url: '/ShenPI/Index',
                        type: 'POST',
                        data: { "stetede": 4, "bians": Binas, "Namesed": Name, "liyou": MMK },
                        success: function (data) {
                            if (data == "驳回通过") {
                                //返回是否是他审批
                                $("#WT_dh_mb").hide();
                                var mbr = $("#JNKMHNB").text()
                                var name = $("#Login_N").text()
                                var BZJG = [];
                                BZJG.push({
                                    Fr_fl: "对外报价审批",//待处理模块
                                    De_tiji: "对外报价被驳回",//待处理内容
                                    Cl_juli: mbr,//接收人
                                    Nd_jiage: name,//发起人
                                    Fr_zhuang: "待处理"//装态
                                })
                                console.log("共" + BZJG.length + "数据");
                                console.log(BZJG);
                                $.ajax({
                                    url: "/Contracts/Addfr",
                                    type: 'POST',
                                    data: JSON.stringify(BZJG),
                                    contentType: "application/json;charset=utf-8",
                                    dataType: "json",
                                    success: function (text) {
                                        alert("驳回成功！")
                                        location.reload(true)
                                    },
                                    error: function (text) {
                                        alert("系统错误" + text);
                                    }
                                })
                            } else {
                                alert("驳回失败！")
                            }

                        },
                        error: function () {
                            alert("系统错误!");
                        }
                    })
                } else {
                    alert("请输入理由！")
                }
            })
            xiashi()
            //显示
            function xiashi() {
                var Binas = $("#txtdan").val()
                var JNSKNM = $("#Login_N").val()
                $.ajax({
                    url: '/ShenPI/Duiw',
                    type: 'POST',
                    data: { "state": 1, "bians": Binas, "Njism": "对外报价" },
                    success: function (data) {
                        console.log(data)
                        $(".BHIDNND tr").remove()
                        $.each(data, function (i, jisd) {
                            console.log(jisd)
                            var $tr = $(`<tr>
                                                <td>${jisd.BOM2_id}</td>
                                                <td>${jisd.Inf_wu}</td>
                                                <td>${jisd.Inf_gong}</td>
                                                <td>${jisd.Inf_JT}</td>
                                                <td>${jisd.BOM2_ST}</td>
                                                <td>${jisd.Inf_huiP}</td>
                                                <td><span>${jisd.OP_LR}</span>%</td>
                                                <td>${jisd.Inf_LI}</td>
                                                <td>${jisd.BOM2_CB}</td>
                                            </tr>`);
                            $(".BHIDNND").append($tr)
                        })
                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            }
            //通过
            $(document).on("click", "#dabiO1", function () {
                var Binas = $("#txtdan").val()
                var Name = $("#Login_sf").text()
                var Njism = "D";
                $.ajax({
                    url: '/ShenPI/Index',
                    type: 'POST',
                    data: { "stetede": 5, "bians": Binas, "Namesed": Name, "Njism": Njism },
                    success: function (data) {
                        if (data == "审批通过") {
                            //返回是否是他审批\
                            var mbr = $("#JNKMHNB").text()
                            var name = $("#Login_N").text()
                            var BZJG = [];
                            BZJG.push({
                                Fr_fl: "对外报价审批",//待处理模块
                                De_tiji: "对外报价通过请继续",//待处理内容
                                Cl_juli: mbr,//接收人
                                Nd_jiage: name,//发起人
                                Fr_zhuang: "待处理"//装态
                            })
                            console.log("共" + BZJG.length + "数据");
                            console.log(BZJG);
                            $.ajax({
                                url: "/Contracts/Addfr",
                                type: 'POST',
                                data: JSON.stringify(BZJG),
                                contentType: "application/json;charset=utf-8",
                                dataType: "json",
                                success: function (text) {
                                    alert(text)
                                    window.location.href = "/Admin/shenpiView";
                                },
                                error: function (text) {
                                    alert("系统错误" + text);
                                }
                            })
                        } else {
                            alert("审批未通过")
                        }


                    },
                    error: function () {
                        alert("系统错误!");
                    }
                })
            })
            $(document).on("click", "#WLcb", function () {
                $.ajax({
                    url: "/ShenPI/Wenjian",
                    type: 'POST',
                    data: { "bian": $("#txtdan").val() },
                    success: function (text) {
                        $("#WT_dh_mb2").css({ "display": "block" })
                        $("#WJ_XZLJ").append($(`<a href="/Contracts/Download_file?path=${text}" id="log_SZ" class="WT_qxbh2">下载</a>`))
                    },
                    error: function (text) {
                        alert("系统错误");
                    }
                })
            })
            $(document).on("click", ".WT_qxbh2", function () {
                $("#WT_dh_mb2").css({ "display": "none" })
                $("#WJ_XZLJ a").remove()
            })
        })
    </script>
}
